package com.ktjy.test;

import com.ktjy.entity.CollectionEntity;
import com.ktjy.entity.Host;
import com.ktjy.entity.NullEntity;
import com.ktjy.entity.Pet;
import com.ktjy.service.PetService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/2  8:32
 */
public class Main {
    @Test
    public void test1() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Pet pet=(Pet)context.getBean("pet1");
        //3.调用方法
        pet.introduce();
    }

    @Test
    public void test2() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Pet pet=(Pet)context.getBean("pet2");
        //3.调用方法
        pet.introduce();
    }

    @Test
    public void test3() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Pet pet=(Pet)context.getBean("pet3");
        //3.调用方法
        pet.introduce();
    }

    @Test
    public void test4() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Pet pet=(Pet)context.getBean("pet4");
        //3.调用方法
        pet.introduce();
    }

    @Test
    public void test5() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Host host=(Host)context.getBean("host1");
        //3.调用方法
        System.out.println(host.getName()+"，"+host.getPet().getName()+"，"+host.getPet().getAge());
    }
    @Test
    public void test6() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Host host=(Host)context.getBean("host2");
        //3.调用方法
        System.out.println(host.getName()+"，"+host.getPet().getName()+"，"+host.getPet().getAge());
    }

    @Test
    public void test7() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Host host=(Host)context.getBean("host3  ");
        //3.调用方法
        System.out.println(host.getName()+"，"+host.getPet().getName()+"，"+host.getPet().getAge());
    }

    @Test
    public void test8() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        CollectionEntity collectionEntity=(CollectionEntity)context.getBean("collectionEntity");
        //3.调用方法
        System.out.println("数组类型："+ Arrays.toString(collectionEntity.getArray()));
        System.out.println("List类型："+collectionEntity.getList());
        System.out.println("Set类型："+collectionEntity.getSet());
        System.out.println("Map类型："+collectionEntity.getMap());
        System.out.println("Properties类型："+collectionEntity.getProps());
    }

    @Test
    public void test9() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        NullEntity nullEntity=(NullEntity)context.getBean("nullEntity");
        //3.调用方法
        System.out.println("emptyValue："+nullEntity.getEmptyValue());
        System.out.println("NullValue："+nullEntity.getNullValue());
    }

    @Test
    public void test10() {
        //1.获取spring的上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        Pet pet=new Pet();
        PetService petService=(PetService) context.getBean("petService");
        //3.调用方法
        petService.save(pet);
    }
}
